/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sdd.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;

/**
 *
 * @author ceu
 */
@Entity
public class Product implements Serializable{
    private static final long serialVersionUID = 3L;
    
    private Long id;
    private Double price;
    private String description;
    private String name;
    private Date dateAdded;
    private Date dateRemoved;
    private Integer stock;
    private String vendor;
    private List<Category> categories;
    private List<Feature> features;
    private List<OrderItem> orderItems;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the price
     */
    //@Pattern(regexp="[0-9]+,[0-9][0-9]")
    public Double getPrice() {
        return price;
    }

    /**
     * @param price the price to set
     */
    public void setPrice(Double price) {
        this.price = price;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the dateAdded
     */
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getDateAdded() {
        return dateAdded;
    }

    /**
     * @param dateAdded the dateAdded to set
     */
    public void setDateAdded(Date dateAdded) {
        this.dateAdded = dateAdded;
    }

    /**
     * @return the dateRemoved
     */
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getDateRemoved() {
        return dateRemoved;
    }

    /**
     * @param dateRemoved the dateRemoved to set
     */
    public void setDateRemoved(Date dateRemoved) {
        this.dateRemoved = dateRemoved;
    }

    /**
     * @return the stock
     */
    public Integer getStock() {
        return stock;
    }

    /**
     * @param stock the stock to set
     */
    public void setStock(Integer stock) {
        this.stock = stock;
    }

    /**
     * @return the vendor
     */
    public String getVendor() {
        return vendor;
    }

    /**
     * @param vendor the vendor to set
     */
    public void setVendor(String vendor) {
        this.vendor = vendor;
    }

    /**
     * @return the categories
     */
    
    @ManyToMany
    @JoinTable(name="PRODUCT_CATEGORY")
    public List<Category> getCategories() {
        return categories;
    }

    /**
     * @param categories the categories to set
     */
    public void setCategories(List<Category> categories) {
        this.categories = categories;
    }
    
    public void addCategory(Category c){
        if(categories==null){
            categories = new ArrayList<Category>();
        }
        categories.add(c);
    }

    /**
     * @return the features
     */
    @OneToMany(mappedBy = "product")
    public List<Feature> getFeatures() {
        return features;
    }

    /**
     * @param features the features to set
     */
    public void setFeatures(List<Feature> features) {
        this.features = features;
    }

    public void addFeature(Feature f) {
       
        if (this.features!=null){
            this.features.add(f);
        }else{
            this.features=new ArrayList<Feature>();
            this.features.add(f);
        }
        
        
    }

    /**
     * @return the orderItems
     */
    @OneToMany(mappedBy = "product")
    public List<OrderItem> getOrderItems() {
        return orderItems;
    }

    /**
     * @param orderItems the orderItems to set
     */
    public void setOrderItems(List<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }

    @Override
    public String toString() {
        return "Product{" + "id=" + id + ", price=" + price + ", description=" + description + ", name=" + name + ", dateAdded=" + dateAdded + ", dateRemoved=" + dateRemoved + ", stock=" + stock + ", vendor=" + vendor + ", categories=" + categories + ", features=" + features + ", orderItems=" + orderItems + '}';
    }
    
    
}
